
package com.ostrich.shopping.base;

import android.content.Intent;
import android.os.Bundle;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;

import androidx.databinding.DataBindingUtil;
import androidx.databinding.ViewDataBinding;
import androidx.fragment.app.Fragment;


public abstract class BaseFragment<VDB extends ViewDataBinding> extends Fragment {
    protected VDB binding;
    public BaseFragment() {

    }
    @Override
    public View onCreateView(LayoutInflater inflater, ViewGroup container,
                             Bundle savedInstanceState) {
        binding = DataBindingUtil.inflate(inflater,getLayout(),container,false);
        initView();
        initListener();
        initData();
        return binding.getRoot();
    }

    @Override
    public void onDestroyView() {
        super.onDestroyView();
        binding = null;
    }

    public abstract int getLayout();
    public abstract void initData();
    public abstract void initView();
    public abstract void initListener();

    public void startActivity(Class tClass){
        Intent intent = new Intent(getActivity(), tClass);
        startActivity(intent);
    }

    public void startActivityBundle(Class tClass,Bundle bundle){
        Intent intent = new Intent(getActivity(), tClass);
        intent.putExtras(bundle);
        startActivity(intent);
    }

}